home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Demos
/
Bowers Development
/
AppMaker 2.0b5
/
Examples
/
PowerPlant
/
Gadgets
/
CGadgetsDoc.cp
< prev
next >
Wrap
Text File
|
1996-03-19
|
6KB
|
261 lines
// CGadgetsDoc.cp -- Document methods
// Created 3/19/96 12:49 PM by AppMaker
#include "CGadgetsDoc.h"
#include "CGadgetsData.h"
#include "CButtons.h"
#include "CTabbedPanel.h"
#include "CSliders.h"
#include "CProgressBars.h"
#include "CPallette.h"
#include "CmdCodes.h"
#include "CAboutDialog.h"
#include <LFile.h>
#include <LPlaceHolder.h>
#include <LPrintout.h>
#include <LWindow.h>
#include <UWindows.h>
#include <String_Utils.h>
const ResIDT prto_PrintView = 201;
const ResIDT STRx_Untitled = 128;
// ---------------------------------------------------------------------------
// • CGadgetsDoc
// ---------------------------------------------------------------------------
CGadgetsDoc::CGadgetsDoc(
LCommander *inSuper)
: LSingleDoc(inSuper)
{
mData = new CGadgetsData();
}
// ---------------------------------------------------------------------------
// • ~CGadgetsDoc
// ---------------------------------------------------------------------------
// Destructor
//
CGadgetsDoc::~CGadgetsDoc()
{
delete mData;
}
//----------
void
CGadgetsDoc::newFile()
{
mData->newData();
MakeWindows();
NameNewDoc(); // Set name of untitled window
}
//----------
void
CGadgetsDoc::openFile(
FSSpec *inFileSpec)
{
mData->openData (inFileSpec);
MakeWindows();
if (mWindow != nil) {
mWindow->SetDescriptor (inFileSpec->name);
}
mIsSpecified = true;
}
// ---------------------------------------------------------------------------
// • MakeWindows
// ---------------------------------------------------------------------------
void
CGadgetsDoc::MakeWindows()
{
mButtons = CButtons::CreateButtons(this, mData);
mTabbedPanel = CTabbedPanel::CreateTabbedPanel(this, mData);
mSliders = CSliders::CreateSliders(this, mData);
mProgressBars = CProgressBars::CreateProgressBars(this, mData);
mPallette = CPallette::CreatePallette(this, mData);
mWindow = mButtons;
}
// ---------------------------------------------------------------------------
// • NameNewDoc
// ---------------------------------------------------------------------------
// Name a new, untitled document window
//
// Untitled windows start with "untitled", then "untitled 1",
// "untitled 2", etc. Old numbers are reused, so there won't be
// gaps in the numbering.
//
// This routine uses a STR# resource to store the "untitled" string,
// which can be localized to different languages. The first string
// is "untitled" and the second is "untitled " (trailing space),
// which is used when appending a number to the name.
void
CGadgetsDoc::NameNewDoc()
{
// Start with the default name("untitled")
Str255 name;
::GetIndString(name, STRx_Untitled, 1);
long num = 0;
while (UWindows::FindNamedWindow(name) != nil) {
// An existing window has the current name
// Increment counter and try again
::GetIndString(name, STRx_Untitled, 2);
num++;
Str15 numStr;
::NumToString(num, numStr);
ConcatPStr(name, numStr);
}
mWindow->SetDescriptor(name); // Finally, set window title
}
// ---------------------------------------------------------------------------
// • IsModified
// ---------------------------------------------------------------------------
// Return whether the Document has changed since the last save
Boolean
CGadgetsDoc::IsModified()
{
mIsModified = mData->IsDirty();
return mIsModified;
}
// ---------------------------------------------------------------------------
// • DoAESave
// ---------------------------------------------------------------------------
// Save Document in the specified file with the specified file type
//
// If file type is fileType_Default, use the normal file type for
// this document
void
CGadgetsDoc::DoAESave(
FSSpec &inFileSpec,
OSType inFileType)
{
mData->DoSaveAs(&inFileSpec); // Write out data
// Change window name
mWindow->SetDescriptor(inFileSpec.name);
}
//----------
void
CGadgetsDoc::DoSave()
{
mData->DoSave();
}
//----------
void
CGadgetsDoc::DoRevert()
{
mData->DoRevert();
}
// ---------------------------------------------------------------------------
// • DoPrint
// ---------------------------------------------------------------------------
// Print the contents of the Document
void
CGadgetsDoc::DoPrint()
{
LPrintout *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
LPlaceHolder *textPlace = (LPlaceHolder *)
thePrintout->FindPaneByID('TBox');
//! textPlace->InstallOccupant(mTextView, atNone);
thePrintout->DoPrintJob();
delete thePrintout;
}
//----------
void
CGadgetsDoc::DoInvokeAbout ()
{
CAboutDialog* dialog = CAboutDialog::CreateAboutDialog(this);
}
//----------
void
CGadgetsDoc::ObeyAboutDialog (void* ioParam)
{
CAboutDialog* dialog = (CAboutDialog *)ioParam;
delete dialog;
}
//----------
Boolean
CGadgetsDoc::ObeyCommand(
CommandT inCommand,
void *ioParam)
{
Boolean cmdHandled = true;
switch (inCommand) {
// +++ Add cases here for the commands you handle
// Remember to add same cases to FindCommandStatus below
// to enable/disable the menu items for the commands
case cmdInvokeAbout:
DoInvokeAbout ();
break;
case cmd_AboutDialog:
ObeyAboutDialog (ioParam);
break;
default:
cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
break;
}
return cmdHandled;
}
//----------
void
CGadgetsDoc::FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
Char16 &outMark,
Str255 outName)
{
outUsesMark = false;
switch (inCommand) {
// +++ Add cases here for the commands you handle
case cmdInvokeAbout:
outEnabled = true;
break;
default:
LSingleDoc::FindCommandStatus(inCommand, outEnabled,
outUsesMark, outMark, outName);
break;
}
}